//
//  PBLifeServeController.m
//  PBHomeDemo
//
//  Created by Playboy on 2018/1/6.
//  Copyright © 2018年 tmkj. All rights reserved.
//

#import "PBLifeServeController.h"
#import "PBLifeServeCell.h"

#define kHEIGHT 220

static NSString * const kPBLifeServeCell = @"PBLifeServeCell";

@interface PBLifeServeController ()
@property (strong, nonatomic) IBOutlet UIWebView *webView;
@end

@implementation PBLifeServeController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self configure];
}
- (void)configure {
    [self configureView];
    [self configureData];
}
- (void)configureView {
//    [self.tableView registerNib:[UINib nibWithNibName:kPBLifeServeCell bundle:nil] forCellReuseIdentifier:kPBLifeServeCell];
//    self.tableView.contentInset = UIEdgeInsetsMake(kHEIGHT, 0, 0, 0);
//    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -kHEIGHT, kScreenWidth, kHEIGHT)];
//    imageView.image = [UIImage imageNamed:@"home_life"];
//    imageView.contentMode = UIViewContentModeScaleAspectFill;
//    imageView.tag = 101;
//    [self.tableView addSubview:imageView];
    
}
- (void)configureData {
    [TMNetwork requestGetWithParam:@{} url:@"/sys/config" callback:^(TMBaseReqModel *model) {
        if (model.code == 200) {
            for (NSDictionary *dic in model.data) {
                if (self.type == 1) {
                    if ([dic[@"label"] isEqualToString:@"service_life_h5"]) {
                        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:dic[@"value"]]];
                        [self.webView loadRequest:request];
                    }
                }else if (self.type == 2) {
                    if ([dic[@"label"] isEqualToString:@"service_life_move_home_h5"]) {
                        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:dic[@"value"]]];
                        [self.webView loadRequest:request];
                    }
                }else if (self.type == 3) {
                    if ([dic[@"label"] isEqualToString:@"service_life_repair_h5"]) {
                        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:dic[@"value"]]];
                        [self.webView loadRequest:request];
                    }
                }
            }
        }
    }];
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    CGPoint point = scrollView.contentOffset;
//    if (point.y < -kHEIGHT) {
//        CGRect rect = [self.tableView viewWithTag:101].frame;
//        rect.origin.y = point.y;
//        rect.size.height = -point.y;
//        [self.tableView viewWithTag:101].frame = rect;
//    }
//}

//#pragma mark - UITableViewDelegate,UITableViewDataSource
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    return 1;
//}
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    PBLifeServeCell *cell = [tableView dequeueReusableCellWithIdentifier:kPBLifeServeCell forIndexPath:indexPath];
//    cell.jumpVC = self;
//    return cell;
//}

#pragma mark - super
- (void)resetNavigationBarItems {
    [super resetNavigationBarItems];
    if (self.type == 1) {
        self.title = @"生活服务";
    }else if (self.type == 2) {
        self.title = @"搬家";
    }else if (self.type == 3) {
        self.title = @"家修";
    }
}

- (void)backBarButtonItemClick:(UIBarButtonItem *)sener {
    if ([self.webView canGoBack]) {
        [self.webView goBack];
    }else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
